Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base native currency price for dApp Staking #1252

Merged
merged 6 commits into from
May 28, 2024

Conversation

Dinonard
Copy link
Member

@Dinonard Dinonard commented May 28, 2024

Pull Request Summary

Fixes an issue with threshold calculation in dApp staking.

The issue happens because the formula for tier threshold update did not account for threshold value saturation.
As ASTR price increased, so did the number of available slots, and as a result, thresholds saturated at the minimum possible value. Number of slots could keep increasing, while the thresholds remained the same.

But as ASTR price dropped, this brought a negative change in the number of slots. Since number of slots was way
larger than the base number of slots, this seemed as a larger change that it was supposed to be, in respect to the current threshold.

This fix changes the way threshold is calculated so that the new_number_of_slots is always compared to the base_number_of_slots. This way ensures thresholds are always updated in respect to what the baseline is.

Note

  • issue was reproduced first using the new unit test
  • fix was verified on a chain fork using chopsticks

@Dinonard Dinonard added shiden related to shiden runtime astar Related to Astar shibuya related to shibuya runtime This PR/Issue is related to the topic “runtime”. labels May 28, 2024
run_for_blocks(1);

assert!(
TierConfig::<Test>::get().number_of_slots > base_number_of_slots,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have assert for number of slots as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean to use to calculate the expected number of slots and compare it with the one in the tier config? (if yes, no problem)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant assert_eq!(TierConfig::<Test>::get().number_of_slots, 120)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but the 120 should be derived from somewhere, right?

I've added the check below this one, but kept the old one to ensure change is in the right direction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking hardcoded number so you can visually verify change. number > base_number can be any number

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formula for calculating number of slots is provided via an associated type, it's not dictated by the dAPp staking pallet itself.

This is why, as per your suggestion, I added this below the existing > check:

        assert_eq!(
            TierConfig::<Test>::get().number_of_slots,
            <Test as Config>::TierSlots::number_of_slots(higher_price),
        );

Only it's not hardcoded but derived from the associated type function call.

ermalkaleci
ermalkaleci previously approved these changes May 28, 2024
@@ -366,6 +366,7 @@ impl TierSlotsFunc for ShidenTierSlots {

parameter_types! {
pub const MinimumStakingAmount: Balance = 50 * SDN;
pub const BaseNativeCurrencyPrice: FixedU128 = FixedU128::from_rational(5, 100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be maybe FixedU128::from_rational(5, 10); ?

Copy link
Member Author

@Dinonard Dinonard May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the baseline is 0.05$

EDIT: You're right, it should be adjusted to be larger for Shiden due to slot number formula change before.

Had a bug in my model spreadsheet, but 0.05$ is correct for Shiden. When calculation formula was changed, we also changed the base number of slots to 55 which matches the price of 5 cents.

PierreOssun
PierreOssun previously approved these changes May 28, 2024
Copy link

Code Coverage

Package Line Rate Branch Rate Health
pallets/dapp-staking-migration/src 0% 0%
pallets/oracle-benchmarks/src 0% 0%
precompiles/dispatch-lockdrop/src 86% 0%
primitives/src 61% 0%
pallets/ethereum-checked/src 79% 0%
pallets/dynamic-evm-base-fee/src 92% 0%
chain-extensions/types/unified-accounts/src 0% 0%
precompiles/dapp-staking-v3/src 90% 0%
pallets/unified-accounts/src 86% 0%
precompiles/dapp-staking-v3/src/test 0% 0%
precompiles/unified-accounts/src 100% 0%
chain-extensions/pallet-assets/src 56% 0%
chain-extensions/types/assets/src 0% 0%
pallets/collator-selection/src 92% 0%
pallets/price-aggregator/src 72% 0%
pallets/astar-xcm-benchmarks/src/fungible 100% 0%
pallets/dapp-staking-v3/src/benchmarking 98% 0%
pallets/static-price-provider/src 52% 0%
precompiles/xcm/src 73% 0%
pallets/astar-xcm-benchmarks/src/generic 100% 0%
pallets/dapp-staking-v3/src 92% 0%
precompiles/substrate-ecdsa/src 74% 0%
chain-extensions/types/xvm/src 0% 0%
precompiles/assets-erc20/src 81% 0%
pallets/dapp-staking-v3/src/test 0% 0%
pallets/xc-asset-config/src 64% 0%
pallets/inflation/src 83% 0%
pallets/dapp-staking-v3/rpc/runtime-api/src 0% 0%
precompiles/sr25519/src 64% 0%
pallets/astar-xcm-benchmarks/src 88% 0%
primitives/src/xcm 64% 0%
precompiles/xvm/src 75% 0%
pallets/xvm/src 54% 0%
chain-extensions/xvm/src 0% 0%
chain-extensions/unified-accounts/src 0% 0%
Summary 78% (3600 / 4635) 0% (0 / 0)

Minimum allowed line rate is 50%

@Dinonard Dinonard merged commit 111d18f into master May 28, 2024
8 checks passed
@Dinonard Dinonard deleted the fix/dapp-staking-threshold-calculation branch May 28, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astar Related to Astar runtime This PR/Issue is related to the topic “runtime”. shibuya related to shibuya shiden related to shiden runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants